package com.house.controller;

import com.common.entity.TbCity;
import com.common.entity.house.HouseResource;
import com.common.response.CommonResponse;
import com.github.pagehelper.PageInfo;
import com.house.service.HouseResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/houseResource")
@CrossOrigin
public class HouseResourceController {

    @Autowired
    private HouseResourceService houseResourceService;

    /**
     * 获取省市区城市信息
     * @param pid
     * @return
     */
    @GetMapping("/getCityList/{pid}")
    public List<TbCity> getCityList(@PathVariable Integer pid){
        return houseResourceService.getCityList(pid);
    }

    /**
     * 获取销售楼盘列表
     * @param page
     * @param size
     * @param houseResource
     * @return
     */
    @PostMapping("/getPage")
    public PageInfo<HouseResource> getPage(
            @RequestParam(value = "page",defaultValue = "1") Integer page,
            @RequestParam(value = "size",defaultValue = "10") Integer size,
            @RequestBody HouseResource houseResource
    ){
        return houseResourceService.getPage(page,size,houseResource);
    }

    /**
     * 获取房屋租赁列表
     * @param page
     * @param size
     * @param houseResource
     * @return
     */
    @PostMapping("/getRentPage")
    public PageInfo<HouseResource> getRentPage(
            @RequestParam(value = "page",defaultValue = "1") Integer page,
            @RequestParam(value = "size",defaultValue = "10") Integer size,
            @RequestBody HouseResource houseResource
    ){
        return houseResourceService.getRentPage(page,size,houseResource);
    }

    /**
     * 修改房屋租赁状态
     * @param id
     * @param status
     * @return
     */
    @PutMapping("/updateStatusById")
    public CommonResponse updateStatusById(
            @RequestParam("id") Long id,
            @RequestParam("status") Integer status
    ){
        return houseResourceService.updateStatusById(id,status);
    }

    /**
     * 删除房源（逻辑删除）
     * @param id
     * @return
     */
    @DeleteMapping("/delete")
    public CommonResponse delete(Long id){
        return houseResourceService.delete(id);
    }

    /**
     * 添加房源信息
     * @param images
     * @param houseResource
     * @return
     */
    @PostMapping("/insert")
    public CommonResponse insert(@RequestParam("images") String[] images,@RequestBody HouseResource houseResource){
        return houseResourceService.insert(houseResource,images);
    }

    /**
     * 为房源绑定经纪人
     * @param id
     * @param brokerId
     * @return
     */
    @PutMapping("/bingBroker")
    public CommonResponse bingBroker(@RequestParam("id")Long id,@RequestParam("brokerId") Long brokerId){
        return houseResourceService.bingBroker(id,brokerId);
    }

    @PostMapping("/insertRent")
    public CommonResponse insertRent(@RequestParam("images") String[] images,@RequestBody HouseResource houseResource){
        return houseResourceService.insertRent(images,houseResource);
    }

}
